const express = require("express"),
    router = express.Router(),
    fileController = require("../controller/fileController");

const fs = require("fs"),
    multer = require("multer"),
    storage = multer.diskStorage({
        destination: function (req, file, cb) {
            if (!fs.existsSync("uploads")) fs.mkdirSync("uploads"); // 检查 uploads 目录是否存在，如果不存在则创建
            cb(null, "uploads/");
        },
        filename: function (req, file, cb) {
            cb(null, file.originalname);
        },
    }),
    upload = multer({ storage: storage });

router.post("/upload", upload.single("file"), fileController.upload); //上传文件

module.exports = router;
